package com.example.mapp.buildSql;

import com.example.entity.SpotCheckPlan;
import com.example.ext.entity.ExtEmergencyRescue;
import com.example.ext.entity.ExtInformation;
import com.example.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by youkun on 2017/10/25.
 */
public class EmergencyRescueMappSql {
    /**
     *
     * 查询的SQL
     * findList
     * @param
     * @return
     */
    public String findlists(ExtEmergencyRescue extEmergencyRescue){
        StringBuffer sb = new StringBuffer();
        sb.append(" select ");
        sb.append("  id AS id, ");
        sb.append("  order_num AS orderNum, ");
        sb.append("  alarm_by AS alarmBy, ");
        sb.append("  alarm_by_phone1 AS alarmByPhone1, ");
        sb.append("  alarm_type AS alarmType, ");
        sb.append("  create_by AS createBy, ");
        sb.append("  create_date AS createDate, ");
        sb.append("  order_status AS orderStatus, ");
        sb.append("  status AS status, ");
        sb.append("  out_elevator_id AS outElevatorId ");

        sb.append("  from emergency_rescue  where out_elevator_id IS NOT NULL ");

        if (StringUtils.isNotEmpty(extEmergencyRescue.getAlarmByPhone1())) {
            sb.append(" and alarm_by_phone1 = '" + extEmergencyRescue.getAlarmByPhone1() + "'");
        }

        if (StringUtils.isNotEmpty(extEmergencyRescue.getOrderNum())) {
            sb.append(" and order_num = '" + extEmergencyRescue.getOrderNum() + "'");
        }

        if (StringUtils.isNotEmpty(extEmergencyRescue.getOutElevatorId())) {
            sb.append(" and out_elevator_id = '" + extEmergencyRescue.getOutElevatorId() + "'");
        }
        if(StringUtils.isNotEmpty(extEmergencyRescue.getStatus())){
            sb.append(" and status = '" + extEmergencyRescue.getStatus() + "'");
        }

        sb.append(" order by create_date desc ");



        return sb.toString();
    }
}
